package com.tlgen.modules.common.controller;

import com.tlgen.modules.common.service.NationService;
import com.tlgen.modules.common.service.dto.NationQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "系统：民族信息")
@RestController
@RequestMapping("/api/nation")
public class NationController {

    private final NationService nationService;

    private static final String ENTITY_NAME = "nation";

    public NationController(NationService nationService) {
        this.nationService = nationService;
    }

    @ApiOperation("返回全部的民族信息")
    @GetMapping(value = "/all")
    @PreAuthorize("@tlgen.check('nation:list')")
    public ResponseEntity<Object> getAll(@PageableDefault(value = 2000, sort = {"id"}, direction = Sort.Direction.ASC) Pageable pageable){
        return new ResponseEntity<>(nationService.queryAll(pageable), HttpStatus.OK);
    }

    @ApiOperation("查询")
    @GetMapping
    @PreAuthorize("@tlgen.check('nation:list')")
    public ResponseEntity<Object> getnations(NationQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(nationService.queryAll(criteria,pageable), HttpStatus.OK);
    }

}
